package cn.itcast.order.web;

import cn.itcast.order.pojo.Order;
import cn.itcast.order.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("order")
@Slf4j
// 添加CrossOrigin注解  会所有来源都允许访问
//@CrossOrigin
public class OrderController {

   @Autowired
   private OrderService orderService;

    @GetMapping("/{orderId}")
    public Order queryOrderByUserId(@PathVariable("orderId") Long orderId, @RequestHeader(required = false,value = "xyz") String Header) {

        log.info("请求头中的信息是：{}",Header);
        // 添加一个响应头
        //response.addHeader("Access-Control-Allow-Origin","http://localhost:8888");

        // 根据id查询订单并返回
        return orderService.queryOrderById(orderId);
    }
}
